<template>
  <el-dialog
    title="任务处理结果"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <!-- :rules="dataRule" -->
    <el-form :model="dataForm" ref="dataForm" label-width="80px">
      <el-form-item label="处理结果:" prop="projectId">
        <el-input
          type="textarea"
          :rows="3"
          :autosize="{ minRows: 1, maxRows: 4 }"
          v-model="dataForm.taskDescription"
          placeholder="任务描述"
        ></el-input>
      </el-form-item>
      <el-form-item label="问题反馈:" prop="projectId">
        <el-input
          type="textarea"
          :rows="3"
          :autosize="{ minRows: 1, maxRows: 4 }"
          v-model="dataForm.taskDescription"
          placeholder="问题反馈"
        ></el-input>
      </el-form-item>
      <el-form-item label="完成时间:" prop="projectId">
        <el-date-picker
          v-model="dataForm.endTime"
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="相关附件" prop="fileUpload">
        <el-upload
          class="upload-demo"
          :action="actionUrl"
          :on-success="successHandle"
          :on-remove="handleRemove"
          :limit="1"
          :file-list="fileList"
          multiple
        >
          <el-button size="small" type="primary">点击上传</el-button>
          <div class="el-upload__tip" slot="tip">文件不超过200mb</div>
        </el-upload>
      </el-form-item>
    </el-form>
    <!-- <el-table :data="taskDetailData">
      <el-table-column
        property="createTime"
        label="日期"
        width="150"
      ></el-table-column>
      <el-table-column
        property="realName"
        label="姓名"
        width="200"
      ></el-table-column>
      <el-table-column property="taskRecord" label="操作"></el-table-column>
      <el-table-column property="fileName" label="文件名称"></el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click="uploadHandle(scope.row.taskDetailId)"
            >下载</el-button
          >
        </template>
      </el-table-column>
    </el-table> -->

    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { treeDataTranslate } from "@/utils";
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        projectId: "",
        taskId: 0,
        projectId: "",
        beginTime: "",
        endTime: "",
        taskName: "",
        taskDescription: "",
        dataListing: "",
        createUserId: "",
        taskStatus: "",
        allocateUserIds: "",
        headUerId: "",
        auditUserId: "",
      },
      taskDetailData: [],
      departList: [],
      departListTreeProps: {
        label: "departmentName",
        children: "children",
      },
      projectList: [],
      actionUrl: "",
      fileList: [],
    };
  },
  methods: {
    init(id) {
      this.dataForm.taskId = id || 0;
      // console.log(JSON.stringify(this.dataForm))
      //上传接口地址
      this.actionUrl = this.$http.adornUrl(
        `/sys/oss/upload?token=${this.$cookie.get("token")}`
      );
      this.visible = true;
      //   this.$nextTick(() => {
      //     this.$refs["dataForm"].resetFields();
      //     if (this.dataForm.taskId) {
      //       this.$http({
      //         url: this.$http.adornUrl(
      //           `/business/task/task-detail/${this.dataForm.taskId}`
      //         ),
      //         method: "get",
      //         params: this.$http.adornParams(),
      //       }).then(({ data }) => {
      //         if (data && data.code === 0) {
      //           console.log(JSON.stringify(data.taskDetail));
      //           this.dataForm.projectId = data.taskDetail.projectId;
      //           this.dataForm.beginTime = data.taskDetail.beginTime;
      //           this.dataForm.endTime = data.taskDetail.endTime;
      //           this.dataForm.taskName = data.taskDetail.taskName;
      //           this.dataForm.taskDescription = data.taskDetail.taskDescription;
      //           this.dataForm.dataListing = data.taskDetail.dataListing;
      //           this.dataForm.createUserId = data.taskDetail.createUserId;
      //           this.dataForm.taskStatus = data.taskDetail.taskStatus;

      //           this.taskDetailData = data.taskDetail.taskDetailVoList;
      //           console.log(JSON.stringify(this.taskDetailData));
      //         }
      //       });
      //     }
      //   });
    },
    // uploadHandle(id) {
    //   console.log(id);
    // },

    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(
              `/business/department/${!this.dataForm.id ? "save" : "update"}`
            ),
            method: "post",
            data: this.$http.adornData({
              id: this.dataForm.id || undefined,
              departmentName: this.dataForm.departmentName,
              parentId: this.dataForm.parentId,
            }),
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                },
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    },

    // 上传成功
    successHandle(response, file, fileList) {
      this.fileList = fileList;
      this.dataForm.filePath = response.url;
      this.dataForm.fileName = file.name;
      console.log("文件路径" + this.dataForm.filePath);
      console.log("文件名称" + this.dataForm.fileName);
      this.successNum++;
      if (response && response.code === 0) {
        this.$message({
          message: "上传成功",
          type: "success",
          duration: 1500,
          onClose: () => {},
        });
        // if (this.num === this.successNum) {
        //   this.$confirm('操作成功, 是否继续操作?', '提示', {
        //     confirmButtonText: '确定',
        //     cancelButtonText: '取消',
        //     type: 'warning'
        //   }).catch(() => {
        //     this.visible = false
        //   })
        // }
      } else {
        this.$message.error(response.msg);
      }
    },
    //删除
    handleRemove(file, fileList) {
      console.log(JSON.stringify(file));
      console.log(JSON.stringify(fileList));
      this.$confirm(`确定删除操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl("sys/oss/delete-file"),
          method: "post",
          params: this.$http.adornParams({
            filePath: file.response.url,
          }),
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "删除成功",
              type: "success",
              duration: 1500,
              onClose: () => {},
            });
          }
        });
      });

      // this.$axios.post('/api/delete',file.name ) //请求头要为表单
      //   .then(response=>{
      //     console.log(response.data);
      //   })
      //   .catch(function (error) {
      //     console.log(error);
      //   })
    },
  },
};
</script>
